﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spring.Data.Generic;
using Spring.Transaction;
using Spring.Transaction.Support;

namespace HotelApp
{
    public static class AppConfigurer
    {
        //Configuration data from initialization 
        private static AdoTemplate _AdoTemplate;
        private static IPlatformTransactionManager _TransactionManager;

        //Configuration data from table app_config
        private static IDictionary<string, IList<string>> _DicKeys = null;

        public static void Config(AdoTemplate template)
        {
            _AdoTemplate = template;
            _TransactionManager = new Spring.Data.Core.AdoPlatformTransactionManager(_AdoTemplate.DbProvider);
        }

        #region properties
        public static AdoTemplate AdoTemplate
        {
            get
            {
                if (_AdoTemplate == null)
                    throw new Exception("Component not initialized");

                return _AdoTemplate;
            }
        }

        public static IPlatformTransactionManager TransactionManager
        {
            get
            {
                if (AppConfigurer._TransactionManager == null)
                    throw new InvalidOperationException("Component not initialized!");

                return _TransactionManager;
            }
        }

        public static ITransactionDefinition TransactionDefinition
        {
            get
            {
                if (AppConfigurer._TransactionManager == null)
                    throw new InvalidOperationException("Component not initialized!");

                DefaultTransactionDefinition def = new DefaultTransactionDefinition();
                def.PropagationBehavior = TransactionPropagation.Required;

                return def;
            }
        }

        public static string DateFormat
        {
            get
            {
                return "yyyy-MM-dd";
            }
        }
        #endregion
    }
}
